home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte11 / getbuttn / phone.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  22KB  |  653 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetButtonInfo";
  16. LPCTSTR lpszTitle   = "phoneGetButtonInfo"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.     HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.     DWORD dwNumDevices;     // number of available devices
  121.     DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN  :
  170.                 pButtonInfo = (PHONEBUTTONINFO *) calloc (1, sizeof(PHONEBUTTONINFO)+1000);
  171.                    pButtonInfo->dwTotalSize = sizeof(PHONEBUTTONINFO)+1000;
  172.                    pButtonInfo->dwButtonMode = PHONEBUTTONMODE_LOCAL;
  173.                    pButtonInfo->dwButtonFunction = PHONEBUTTONFUNCTION_MUTE;
  174.                    pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  175.                    pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  176.                   phoneGetDevCaps(myInfo.phoneApp, OWNER, myInfo.dwAPIVersion, myInfo.dwExtVersion, 
  177.                                         pPhoneCaps);
  178.                
  179.                if (pPhoneCaps->dwNumButtonLamps > 0)
  180.                    {
  181.                             
  182.                        lRet = phoneSetButtonInfo(myPhoneInfo[OWNER].hPhone, (pPhoneCaps->dwNumButtonLamps - 1), pButtonInfo);
  183.                        if (lRet > 0)
  184.                      {
  185.                       myPhoneInfo[OWNER].dwRequestID = lRet;
  186.                      wsprintf(buf, "phoneSetButtonInfo proceeding!");
  187.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  188.                      }
  189.                         else 
  190.                      {
  191.                            wsprintf( buf,"phoneSetButtonInfo failed, err=x%lx", lRet);
  192.                          phoneError(lRet);
  193.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  194.                      }    
  195.                    }
  196.                    else
  197.                    {
  198.                        wsprintf( buf,"No button/lamp pairs are detectable by TAPI.");
  199.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  200.                      phoneError(lRet);
  201.                        break;
  202.                    }
  203.                     
  204.                     lRet = phoneGetButtonInfo(myPhoneInfo[OWNER].hPhone, (pPhoneCaps->dwNumButtonLamps - 1), pButtonInfo);
  205.                     if (lRet == 0)
  206.                   {
  207.                   wsprintf(buf, "phoneGetButtonInfo succeeded!");
  208.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  209.                         wsprintf(buf, "The Button Mode is x%lx", pButtonInfo->dwButtonMode);
  210.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  211.                   wsprintf(buf, "The Button Function is x%lx", pButtonInfo->dwButtonFunction);
  212.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  213.                   }
  214.                      else 
  215.                   {
  216.                         wsprintf( buf,"phoneGetButtonInfo failed, err=x%lx", lRet);
  217.                       phoneError(lRet);
  218.                   }    
  219.                 
  220.                     free (pButtonInfo);
  221.                break;
  222.                   
  223.          
  224.             case IDM_EXIT :
  225.                for (i = 0; i < myInfo.dwNumDevices; i++)
  226.                     phoneClose(myPhoneInfo[i].hPhone);
  227.                 
  228.                    phoneShutdown(myInfo.phoneApp);
  229.                DestroyWindow( hWnd );
  230.                break;
  231.  
  232.                 
  233.             case IDM_ABOUT :
  234.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  235.                 break;         
  236.          }
  237.                 
  238.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  239.  
  240.       
  241.        case WM_CREATE :
  242.  
  243.           hdc = GetDC (hWnd) ;
  244.           GetTextMetrics (hdc, &tm) ;
  245.           ReleaseDC (hWnd, hdc) ;
  246.           
  247.           hListWnd = CreateWindowEx( 0, "listbox", 
  248.                         " ",    
  249.                         WS_CHILD | WS_VISIBLE,  
  250.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  251.                         tm.tmAveCharWidth * 16 +
  252.                                    GetSystemMetrics (SM_CXVSCROLL), 
  253.                         tm.tmHeight * 5,  
  254.                         hWnd,              
  255.                         NULL,              
  256.                         hInst,         
  257.                         NULL               
  258.                         );
  259.       
  260.              //phoneInitialize
  261.                //...............................................
  262.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  263.             if (lRet == 0) 
  264.             {
  265.                 
  266.                wsprintf(buf, "phoneInitialize succeeded!");
  267.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  268.             }
  269.                
  270.                else 
  271.                {
  272.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  273.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  274.                     phoneError(lRet);
  275.                     break;
  276.             }                    
  277.                
  278.             //phoneNegotiateAPIVersion
  279.                   //...............................................
  280.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  281.                                                     &myInfo.dwAPIVersion, &ext_id);
  282.             if (lRet == 0)                        
  283.             {
  284.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  285.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  286.             }
  287.                   else 
  288.                   {
  289.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  290.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  291.                     phoneError(lRet);
  292.                     phoneShutdown(myInfo.phoneApp);
  293.                break;
  294.              }
  295.  
  296.                //phoneNegotiateExtVersion
  297.                //...............................................
  298.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  299.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  300.             if (lRet == 0)                        
  301.             {
  302.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  303.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  304.               }
  305.                   else 
  306.                {
  307.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  308.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  309.                       phoneError(lRet);
  310.                }
  311.  
  312.             //phoneOpen
  313.                //................................................................
  314.                for (i = 0; i < myInfo.dwNumDevices; i++)
  315.                {
  316.                    if ( i == 0)
  317.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  318.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  319.                    else
  320.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  321.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  322.                    
  323.                    if (lRet == 0)
  324.                    {
  325.                      wsprintf(buf, "phoneOpen succeeded!");
  326.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  327.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  328.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  329.                          
  330.                       phoneGetDevCaps(myInfo.phoneApp,i,
  331.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  332.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  333.                   strcat( buf, " is the phone providor's name." );
  334.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  335.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  336.                      
  337.                   if (i == 0)
  338.                   {
  339.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  340.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  341.                   }
  342.                   else
  343.                   {
  344.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  345.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  346.                   }
  347.                }
  348.                    else 
  349.                    {
  350.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  351.                        phoneError(lRet);
  352.                    }
  353.                   } 
  354.  
  355.             free (pPhoneCaps);
  356.             break;
  357.       
  358.       case WM_SIZE:
  359.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  360.          break;
  361.  
  362.       case WM_DESTROY :
  363.          PostQuitMessage(0);
  364.          break;
  365.             
  366.       default :
  367.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  368.    }
  369.  
  370.    return( 0L );
  371. }
  372.  
  373.  
  374.  
  375.  
  376. /****************************************************************************
  377.     FUNCTION: phoneCallback
  378.     PURPOSE:  callback function handles phone events
  379. ****************************************************************************/
  380. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  381.                                 DWORD dwCallbackInst, DWORD dwParam1,
  382.                                 DWORD dwParam2,DWORD dwParam3)
  383. {
  384.     
  385.     switch (dwMsg)
  386.     {
  387.         case PHONE_REPLY:
  388.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  389.                    if (dwParam2 != 0)
  390.                 {
  391.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  392.                        phoneError(lRet);
  393.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  394.                    }
  395.             break;       
  396.  
  397.         case PHONE_STATE:
  398.         
  399.             if (dwParam1 == PHONESTATE_RINGMODE)
  400.             {
  401.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  402.                 if (lRet == 0)
  403.                {
  404.                 wsprintf(buf, "phoneGetRing succeeded!");
  405.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  406.                if (dwRingMode == 0)
  407.                     {
  408.                         wsprintf(buf, "The phone device is currently not ringing.");
  409.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  410.                }
  411.                     else
  412.                     {
  413.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  414.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  415.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  416.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  417.                     }
  418.                }
  419.                  else 
  420.                {
  421.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  422.                    phoneError(lRet);
  423.                }        
  424.               
  425.               break;
  426.               }
  427.             
  428.  
  429.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  430.             {   
  431.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  432.                 if (lRet == 0)
  433.                {
  434.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  435.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  436.                
  437.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  438.                     {
  439.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  440.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  441.                     }
  442.                     else
  443.                     {
  444.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  445.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  446.                     }
  447.  
  448.               }
  449.                  else 
  450.                {
  451.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  452.                    phoneError(lRet);
  453.                }    
  454.             break;                
  455.             }
  456.  
  457.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  458.             {   
  459.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  460.                if (lRet == 0)
  461.                {
  462.                 wsprintf(buf, "phoneGetVolume succeeded!");
  463.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  464.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  465.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  466.                }
  467.                  else 
  468.                {
  469.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  470.                    phoneError(lRet);
  471.                }    
  472.             break;                
  473.             }
  474.  
  475.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  476.             {   
  477.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  478.                 if (lRet == 0)
  479.                {
  480.                   wsprintf(buf, "phoneGetGain succeeded!");
  481.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  482.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  483.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  484.                }
  485.                  else 
  486.                {
  487.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  488.                     phoneError(lRet);
  489.                }
  490.             break;                
  491.             }
  492.             
  493.             if (dwParam1 == PHONESTATE_DISPLAY)
  494.             {   
  495.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  496.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  497.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  498.                 if (lRet == 0)
  499.                {
  500.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  501.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  502.                strcpy(buf, lpszTitle);
  503.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  504.                strcat( buf, " is the current phone display." );
  505.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  506.                }
  507.                  else 
  508.                {
  509.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  510.                   phoneError(lRet);
  511.                }    
  512.                     
  513.                 free (pVarString);
  514.                 break;
  515.               }
  516.    }
  517.    return (TRUE);
  518.  
  519.  
  520. /****************************************************************************
  521.     FUNCTION: phoneError
  522.     PURPOSE:  phone error messages
  523. ****************************************************************************/
  524. void phoneError (LONG lrc)
  525. {
  526.  switch (lrc) {
  527.     case PHONEERR_INVALAPPHANDLE:
  528.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  529.        break;
  530.     case PHONEERR_BADDEVICEID:
  531.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  532.                    MB_OK);
  533.        break;
  534.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  535.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  536.        break;
  537.     
  538.     case PHONEERR_INVALBUTTONLAMPID:
  539.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  540.        break;
  541.  
  542.     case PHONEERR_INVALBUTTONMODE:
  543.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  544.        break;
  545.  
  546.     case PHONEERR_INVALBUTTONSTATE:
  547.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  548.        break;
  549.  
  550.     case PHONEERR_INUSE:
  551.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  552.        break;
  553.     
  554.     case PHONEERR_INVALHOOKSWITCHDEV:
  555.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  556.        break;
  557.  
  558.     case PHONEERR_INVALHOOKSWITCHMODE:
  559.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  560.        break;
  561.  
  562.     case PHONEERR_INVALLAMPMODE:
  563.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  564.        break;
  565.      
  566.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  567.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  568.        break;
  569.     case PHONEERR_NOMEM:
  570.        MessageBox (hWnd, "No memory","", MB_OK);
  571.        break;
  572.     case PHONEERR_NODRIVER:
  573.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  574.        break;
  575.     case PHONEERR_RESOURCEUNAVAIL:
  576.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  577.        break;
  578.     case PHONEERR_ALLOCATED:
  579.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  580.        break;
  581.     case PHONEERR_INVALDATAID:
  582.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  583.        break;
  584.     case PHONEERR_INVALDEVICECLASS:
  585.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  586.        break;
  587.     case PHONEERR_INVALPOINTER:
  588.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  589.                    "", MB_OK);
  590.        break;
  591.     case PHONEERR_OPERATIONFAILED:
  592.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  593.        break;
  594.     case PHONEERR_INVALPHONEHANDLE:
  595.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  596.        break;
  597.     case PHONEERR_INVALPHONESTATE :
  598.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  599.        break;
  600.     case PHONEERR_INVALPRIVILEGE:
  601.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  602.        break;
  603.     case PHONEERR_NODEVICE:
  604.        MessageBox (hWnd, "No associated device for given class",
  605.                    "", MB_OK);
  606.        break;
  607.     case PHONEERR_OPERATIONUNAVAIL:
  608.        MessageBox (hWnd, "The operation is unavailable",
  609.                    "", MB_OK);
  610.        break;
  611.     case PHONEERR_INVALPARAM:
  612.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  613.        break; 
  614.  
  615.     case PHONEERR_INVALRINGMODE:
  616.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  617.        break; 
  618.  
  619.     }
  620.     
  621.              
  622. }
  623.  
  624. LRESULT CALLBACK About( HWND hDlg,           
  625.                         UINT message,        
  626.                         WPARAM wParam,       
  627.                         LPARAM lParam)
  628. {
  629.    switch (message) 
  630.    {
  631.        case WM_INITDIALOG: 
  632.                return (TRUE);
  633.  
  634.        case WM_COMMAND:                              
  635.                if (   LOWORD(wParam) == IDOK         
  636.                    || LOWORD(wParam) == IDCANCEL)    
  637.                {
  638.                        EndDialog(hDlg, TRUE);        
  639.                        return (TRUE);
  640.                }
  641.                break;
  642.    }
  643.  
  644.    return (FALSE); 
  645. }
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.